//################################################################################################################################//
//##                                                                                                                            ##//
//## This page is designed and developed to implement "Dentist Recommendation  "(My Find A Doc HealthCare-IV)                                                                  ##//
//##                                                                                                                            ##//
//## Author   : Akash Saxena                                                                                                          ##//
//## Dated    : 17 Sep '07                                                                                                   ##//
//##                                                                                                                            ##//
//################################################################################################################################//


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class Dentist_Recommend : System.Web.UI.Page
{
    //Create object of Dentist and manager Class.
    clsDentist objDentist = new clsDentist();
    Manager objManager = new Manager(true,"ConnectionString");
    string strMsg = "";
    int iUserid = 0;
    string sLoginname = "";
    string sUserEmail = "";
    int iDentistId = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        localFunction lfunction = new localFunction();
        //Check User Login.
        lfunction.checkPatientLogin(true);

        if (Request.QueryString["Id"] != null && Request.QueryString["Id"].ToString().Trim() != "")
        {
            if (Manager.IsNumeric(Request.QueryString["Id"].ToString()))
            {
                iDentistId = Convert.ToInt32(Request.QueryString["Id"]);
            }
        }
        else
        {
            iDentistId = 0;
        }



        if (Session["LoginName"] != null && Session["LoginName"].ToString().Trim() != "")
        {
            sLoginname = Session["LoginName"].ToString();
        }

        if (Session["userID"] != null && Session["userID"].ToString().Trim() != "")
        {

            iUserid = Convert.ToInt32(Session["userID"]);
        }
        else
        {
            iUserid = 0;
        }

        if (Session["useremail"] != null && Session["useremail"].ToString().Trim() != "")
        {
            sUserEmail = Session["useremail"].ToString();
        }
    }

    protected void btnRecommend_Click(object sender, EventArgs e)
    {
        localFunction lfunctionobj = new localFunction();
        string strDentistName = "";

        SqlDataReader objDataReader = null;
        objDataReader = objManager.ExecuteQuery("select (fname +' ' + MName + ' '+ LName)as Name from tbl_dentists where id=" + iDentistId);
        if (objDataReader.HasRows)
        {
            objDataReader.Read();
            strDentistName = objDataReader["Name"].ToString();
        }
        //Retrive Dentist view Profile URL.
      //  string strURL = Request.ApplicationPath + "/Dentist/DentistDetails.aspx?id=" + iDentistId;
        if (txtRecommend1.Text == "" && txtRecommend2.Text == "" && txtRecommend3.Text == "" && txtRecommend4.Text == "" && txtRecommend5.Text == "")
        {
            lblMsg.Text = "Enter at least one EmailId ";
            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Font.Bold = true;

        }
        else
        {
            string EmailIds = "";
            if (txtRecommend1.Text.Trim().Length > 0)
            {
                EmailIds = txtRecommend1.Text.Trim();
            }

            if (txtRecommend2.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend2.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend2.Text.Trim();
            }
            if (txtRecommend3.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend3.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend3.Text.Trim();
            }
            if (txtRecommend4.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend4.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend4.Text.Trim();
            }
            if (txtRecommend5.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend5.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend5.Text.Trim();
            }

            if (Session["strHttp"] != null)
            {
                //Comented for implement new URL Formate at 17/07/08 by Ranjeet 
                //strMsg = sLoginname + " " + "has recommended Dr." + strDentistName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='" + Session["strHttp"].ToString() + "/Dentist/DentistDetails.aspx?id=" + iDentistId + "'> Click Here</a>";
                string dentdetailsURL = "";
                dentdetailsURL = HttpContext.Current.Session["strHttp"] + "dentists/" + lfunctionobj.GetURLFormatById(iDentistId, "DENTIST") + "/" + iDentistId.ToString() + "-" + strDentistName + ".aspx";

                strMsg = sLoginname + " " + "has recommended Dr." + strDentistName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='" + dentdetailsURL + "'> Click Here</a>";
            }
            else
            {
                //Comented for implement new URL Formate at 17/07/08 by Ranjeet 
                //strMsg = sLoginname + " " + "has recommended Dr." + strDentistName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='http://www.findadoc.com/Dentist/DentistDetails.aspx?id=" + iDentistId + "'>Click Here</a>";

                string dentdetailsURL = "";
                dentdetailsURL = lfunctionobj.GetURLFormatById(iDentistId, "DENTIST") + "/" + iDentistId.ToString() + "-" + strDentistName + ".aspx";
                strMsg = sLoginname + " " + "has recommended Dr." + strDentistName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='http://www.findadoc.com/Dentists/'" + dentdetailsURL + "''>Click Here</a>";
            }
            
            objManager.sendMail(strMsg, EmailIds, sLoginname, "Recommend to a Dentist", sUserEmail, "");
            lblMsg.Text = "Message has sent successfully";

        }
        objDataReader.Close();
        objDataReader.Dispose();
    }
    
}
